<?php

namespace App\Containers\AppSection\Questionnaire\UI\API\Transformers;

use App\Containers\AppSection\Questionnaire\Models\Questionnaire;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;

class QuestionnaireTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'responses'
    ];

    /**
     * @var  array
     */
    protected array $availableIncludes = [

    ];

    public function transform(Questionnaire $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'created_at' => $this->dateFormatter($t->created_at),
            'updated_at' => $this->dateFormatter($t->updated_at),
            'readable_created_at' => $t->created_at->diffForHumans(),
            'readable_updated_at' => $t->updated_at->diffForHumans()
        ];
    }

    public function includeResponses(Questionnaire $t): Collection
    {
        return $this->collection($t->responses, new ResponseTransformer);
    }
}
